Kinetis SDK Demo Applications User Guide  1.0.0-beta
Freescale Semiconductor, Inc. Confidential - NDA only
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Getting started

1. Hardware settings

DSPI eDMA Demo program needs the following hardware:

  • TWR-K64F120M, FRDMK64F120M

2. Download program

  • Download the program to the target board.
  • Connect a USB cable to the PC host and open a serial terminal at 115200 baud, 8-bits no parity, 1 stop bit.
  • When successfully connected, the program sends "Press spacebar to begin." to the terminal. Then you should press space key to continue. Communication Interface Settings:
    • TWR-K64F120M(OpenSDA) UART1, TX: PTC3 RX: PTC4.
    • FRDM-K64F120M(OpenSDA) UART0, TX: PTB16 RX: PTB17.

3. Run the program

The following will appear in the terminal window:


DSPI eDMA Demo

DSPI Transfers using eDMA



Configuration:

Setting Value
Terminal Baud: 115200 bps
TDSPI Bit rate: 5000 bps
TDSPI Master: DSPI0
TDSPI Slave: DSPI1


Connection on TWR-K64F120M:

Master Slave
SS PTD0 PTB10
SCK PTD1 PTB11
MstOut PTD2 PTB17 SlvIn
MstIn PTD3 PTB16 SlvOut


Connection on FRDM-K64F120M:

Master Slave
SS PTD0 PTD4
SCK PTD1 PTD5
MstOut PTD2 PTD7 SlvIn
MstIn PTD3 PTD6 SlvOut

This indicates the speed of the SPI transfers, and what pins to connect and how to connect them.

Key Functions

1.

void dspi_edma_master_setup(uint8_t instance, uint32_t baudRateHz, uint8_t transferSizeBits)

Takes in the DSPI module instance, the desired data rate of DSPI transfers, and the frame size of the data transfer. Initializes master instance of DSPI.

Parameters
instanceDSPI module instance
baudRateHzPass in the desired baud rate of DSPI transfers in Hz.
transferSizeBitsPass data frame size (8 or 16 bit)

2.

void dspi_edma_slave_setup(uint8_t instance, uint8_t transferSizeBits)

Takes in the DSPI module instance, and the frame size of the data transfer. Initializes slave instance of DSPI.

Parameters
instanceDSPI module instance
transferSizeBitsPass data frame size (8 or 16 bit)

3.

dspi_status_t data_source(uint8_t * sourceWord, uint32_t instance)

Callback function for DSPI slave. Used to transmit data from slave. In this application it generates slave data out, the data out is a count.

Parameters
sourceWord8-bit data variable to be passed to slave PUSHR register.
instanceInstance of the DSPI module.

4.

void on_error(dspi_status_t error, uint32_t instance)

Callback function for DSPI slave. Used to handle errors. In this application is sets the error flag to signal the end of the demonstration.

Parameters
errorUses dspi_status_t value given by driver interrupt handler.
instanceInstance of the DSPI module.

5.

void setup_edma_loop(edma_loop_setup_t *loopSetup, uart_state_t *uart)

Configures an eDMA transfer loop using a loopSetup structure, and if a valid uart_state_t is passed will print out the TCD for that loop.

Parameters
loopSetupData structure defined by user, containing all the parameters for the eDMA loop.
uartPointer to a valid uart_state_t for debug printing.

6.

void disable_edma_loop(edma_loop_setup_t *loopSetup, uart_state_t *uart)

Disables user configured eDMA transfer loop. Also, will free memory allocated by eDMA transfer loop. If a valid uart_state_t is passed will print out the TCD for that loop.

Parameters
loopSetupData structure defined by user, containing all the parameters for the eDMA loop.
uartPointer to a valid uart_state_t for debug printing.

7.

void *mem_align(size_t ptrSize, uint32_t alignment)

Function to peform aligned data memory allocation. Useful when memalign is not available.

Parameters
ptrSizesize_t variable to pass size of memory to be allocated
alignmentuint32_t variable to pass byte size to align data with
Returns
pointer to aligned & allocated memory

8.

void free_align(void *ptr)

Function to free memory allocated by mem_align

Parameters
ptrpointer that has been allocated with mem_align